<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>成品库存</title>
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="../../static/css/lib/bootstrap3.4.1.min.css" th:href="@{/css/lib/bootstrap3.4.1.min.css}">
    <!-- Bootstrap-table CSS-->
    <link rel="stylesheet" href="../../static/css/lib/bootstrap-table.min.css" th:href="@{/css/lib/bootstrap-table.min.css}">
    <!-- jquery-ui CSS-->
    <link rel="stylesheet" href="../../static/css/lib/jquery-ui.min.css" th:href="@{/css/lib/jquery-ui.min.css}">
    <!-- select2 CSS-->
    <link rel="stylesheet" href="../../static/css/lib/select2.min.css" th:href="@{/css/lib/select2.min.css}">
    <link rel="stylesheet" href="../../static/css/lib/select2-bootstrap.min.css" th:href="@{/css/lib/select2-bootstrap.min.css}">
    <link href="../../static/css/file.css" rel="stylesheet" th:href="@{/css/file.css}">
    <link href="../../static/css/table.css" rel="stylesheet" th:href="@{/css/table.css}">
</head>

<body onload="init();">

    <div class="panel-body" style="padding-bottom:0;">
        <div class="panel panel-default">
            <div class="panel-heading">查询条件</div>
            <div class="panel-body">
                <div class="form-group" style="margin-top:15px">
                    <div class="row row-gap">
                        <label class="control-label col-sm-2 label-font" for="txt_search_order_number">订单号</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="txt_search_order_number">
                        </div>

                        <label class="control-label col-sm-2 label-font" for="txt_search_job_ticket_number">工作传票号</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="txt_search_job_ticket_number">
                        </div>
                    </div>

                    <div class="row row-gap">
                        <label class="control-label col-sm-2 label-font" for="txt_search_item_name">品名</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="txt_search_item_name">
                        </div>

                        <label class="control-label col-sm-2 label-font" for="txt_search_spec">规格</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="txt_search_spec">
                        </div>
                    </div>

                    <div class="row row-gap">
                        <label class="control-label col-sm-2 label-font" for="txt_search_code">客户代码</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="txt_search_code">
                        </div>

                        <label class="control-label col-sm-2 label-font" for="txt_search_product_number">客户料号</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="txt_search_product_number">
                        </div>
                    </div>

                    <div class="row row-gap">
                        <label class="control-label col-sm-2 label-font" for="txt_search_start_time" title="开始时间">开始时间</label>
                        <div class="col-sm-4">
                            <input type="datetime-local" class="form-control" id="txt_search_start_time">
                        </div>

                        <label class="control-label col-sm-2 label-font" for="txt_search_end_time" title="结束时间">结束时间</label>
                        <div class="col-sm-4">
                            <input type="datetime-local" class="form-control" id="txt_search_end_time">
                        </div>
                    </div>

                    <div class="row row-gap">
                        <label class="control-label col-sm-2 label-font" for="txt_search_is_allocation">是否调拨</label>
                        <div class="col-sm-4">
                            <select class="form-control" id="txt_search_is_allocation">
                                <option>--请选择--</option>
                                <option>是</option>
                                <option>否</option>
                            </select>
                        </div>

                        <label class="control-label col-sm-2 label-font" for="txt_search_house_name">存放仓库</label>
                        <div class="col-sm-4">
                            <select class="form-control" id="txt_search_house_name">
                            </select>
                        </div>
                    </div>

                    <div class="row row-gap">
                        <div class="col-sm-offset-4" style="text-align:left;">
                            <button type="button" style="margin-left:50px" id="btn_filter" class="btn btn-primary" onclick="filter();">过滤</button>
                            <button type="button" style="margin-left:50px" id="btn_reset_filter" class="btn btn-primary" onclick="init();">重置过滤</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <h2 style="font-size: 18px; color: red;">销售部分严格按照入库日期先进行先进先出管理，直到当前最老批次出库完，才能进入下一批次的出库。当入库日期处于同一天，按所需随机出库</h2>
        <div id="toolbar" class="btn-group">
            <button id="btn_add" type="button" class="btn btn-default" onclick="initSale();">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>成品销售
            </button>
            <button id="btn_allocation" type="button" class="btn btn-default" onclick="initAllocation();">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>成品调拨
            </button>
            <button id="btn_export" type="button" class="btn btn-default" onclick="exportExcel();">
                <span class="glyphicon glyphicon-export" aria-hidden="true"></span>批量导出
            </button>
        </div>
        <table id="table"></table>
    </div>

    <!-- 模态框（Modal） 成品销售 -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="min-width: 800px">
            <div class="modal-content">
                <div class="modal-header">
                    <h2 class="modal-title text-center" id="addModalLabel">
                        成品销售信息
                    </h2>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" onsubmit="return false;">
                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font" for="input_export_number">出货单号</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" id="input_export_number"  title="出货单号" onchange="numberInputChange('input_export_number', '出货单号不能为负数')">
                            </div>
                        </div>
                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font" for="code_select">客户代码</label>
                            <div class="col-sm-10">
                                <select class="js-data-example-ajax form-control" id="code_select" title="客户代码" onchange="setInputSuccess($('#code_select'));">
                                </select>
                            </div>
                        </div>

                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font" for="input_bill_of_sale_number">客户订单号</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" id="input_bill_of_sale_number" title="客户订单号" onchange="numberInputChange('input_bill_of_sale_number', '客户订单号不能为负数')">
                            </div>
                        </div>

                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font" for="input_product_number">客户料号</label>

                            <div class="col-sm-10">
                                <input disabled class="form-control"  id="input_product_number" title="客户料号">
                            </div>
                        </div>

                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font">出库数量</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" id="input_export_amount" title="出库数量" onchange="exportAmountInputChange();" >
                            </div>
                        </div>

                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font" for="input_export_date">销售日期</label>
                            <div class="col-sm-10">
                                <input type="date" class="form-control" id="input_export_date" title="销售日期" onchange="checkInputChange('input_export_date')">
                            </div>
                        </div>

                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font" for="storage_date_select">入库日期</label>
                            <div class="col-sm-10">
                                <select class="js-data-example-ajax form-control" id="storage_date_select" title="入库日期" >
                                </select>
                            </div>
                        </div>

                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font">备注</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="6" id="input_remark" title="备注"></textarea>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-success" onclick="sale();">添加</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>

    <!-- 模态框（Modal） 成品调拨 -->
    <div class="modal fade" id="allocationModal" tabindex="-1" role="dialog" aria-labelledby="allocationModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="min-width: 800px">
            <div class="modal-content">
                <div class="modal-header">
                    <h2 class="modal-title text-center" id="allocationModalLabel">
                        成品调拨信息
                    </h2>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" onsubmit="return false;">
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font" for="input_item_name">品名</label>
                            <div class="col-sm-10">
                                <input disabled type="text"   class="form-control" id="input_item_name"  title="品名" >
                            </div>
                        </div>

                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font" for="input_spec">规格</label>
                            <div class="col-sm-10">
                                <input disabled type="text"   class="form-control" id="input_spec"  title="规格" >
                            </div>
                        </div>

                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font" for="input_storage_amount">库存数量</label>
                            <div class="col-sm-10">
                                <input disabled type="number" class="form-control" id="input_storage_amount"  title="库存数量" >
                            </div>
                        </div>

                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font">存放仓库</label>
                            <div class="col-sm-10">
                                <input disabled class="form-control" type="text" id="input_warehouse" title="存放仓库" >
                            </div>
                        </div>

                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font" for="input_allocation_amount">调拨数量</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" id="input_allocation_amount" title="调拨数量" onchange="allocationAmountInputChange();" >
                            </div>
                        </div>

                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font" for="input_allocation_date">调拨日期</label>
                            <div class="col-sm-10">
                                <input type="date" class="form-control" id="input_allocation_date" title="调拨日期" onchange="checkInputChange('input_allocation_date')">
                            </div>
                        </div>

                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label label-font" for="house_name_select">零品存放仓库</label>
                            <div class="col-sm-10">
                                <select class="js-data-example-ajax form-control" id="house_name_select" title="零品存放仓库" onchange="setInputSuccess($('#house_name_select'));">
                                </select>
                            </div>
                        </div>

                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label label-font" for="input_allocation_remark">备注</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="6" id="input_allocation_remark" title="备注"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" onclick="allocation();">添加</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>

    <!-- 模态框（Modal） -->
    <div class="modal fade" id="viewModal" tabindex="-1" role="dialog" aria-labelledby="viewModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="viewModalLabel">
                        查看成品信息
                    </h4>
                </div>
                <div class="modal-body">
                    <table class="table">
                        <caption>成品信息</caption>
                        <tbody>
                        <tr>
                            <td>客户代号</td>
                            <td id="view_code">xxx</td>
                        </tr>
                        <tr>
                            <td>规格</td>
                            <td id="view_spec">xxx</td>
                        </tr>
                        <tr>
                            <td>库存数量</td>
                            <td id="view_storage_amount">xxx</td>
                        </tr>
                        <tr>
                            <td>存放仓库</td>
                            <td id="view_house_name">xxx</td>
                        </tr>
                        <tr>
                            <td>客户料号</td>
                            <td id="view_product_number">xxx</td>
                        </tr>
                        <tr>
                            <td>单位</td>
                            <td id="view_unit">xxx</td>
                        </tr>
                        <tr>
                            <td>单价</td>
                            <td id="view_unit_price">xxx</td>
                        </tr>
                        <tr>
                            <td>入库时间</td>
                            <td id="view_storage_date">xxx</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>

<!-- JavaScript files-->
<!-- jquery.js -->
<script src="../../static/js/lib/jquery.min.js" th:src="@{/js/lib/jquery.min.js}"></script>
<!-- Bootstrap.js -->
<script src="../../static/js/lib/bootstrap3.4.1.min.js" th:src="@{/js/lib/bootstrap3.4.1.min.js}"></script>
<!-- Bootstrap-table.js -->
<script src="../../static/js/lib/bootstrap-table.min.js" th:src="@{/js/lib/bootstrap-table.min.js}"></script>
<script src="../../static/js/lib/bootstrap-table-zh-CN.min.js" th:src="@{/js/lib/bootstrap-table-zh-CN.min.js}"></script>
<!-- sweetalert2.js -->
<script src="../../static/js/lib/sweetalert.min.js" th:src="@{/js/lib/sweetalert.min.js}"></script>
<script src="../../static/js/lib/es6-promise.auto.min.js" th:src="@{/js/lib/es6-promise.auto.min.js}"></script>
<!-- jquery-ui.js -->
<script src="../../static/js/lib/jquery-ui.min.js" th:src="@{/js/lib/jquery-ui.min.js}"></script>
<!-- select2.js -->
<script src="../../static/js/lib/select2.min.js" th:src="@{/js/lib/select2.min.js}"></script>
<script src="../../static/js/lib/Select2-zh-CN.js" th:src="@{/js/lib/Select2-zh-CN.js}"></script>
<script src="../../static/js/common.js" th:src="@{/js/common.js}"></script>
<script src="../../static/js/dragModel.js" th:src="@{/js/dragModel.js}"></script>
<script>
    /** 初始化 */
    let $table = $('#table');
    let $houseNameSelect = $("#house_name_select");
    let $codeSelect =$("#code_select");
    let $exportAmountInput = $("#input_export_amount");
    let $allocationAmountInput = $("#input_allocation_amount");
    let $storageDateSelect = $("#storage_date_select");

    let i = 0;
    let storageDateArray = [];

    // 服务器分页获取数据
    function getServerPaging(node, url, queryParams) {
        initTable(node, url, [10, 20, 30, 40, 50, 60, "All"], queryParams, [{
                checkbox: true
            }, {
                field: 'orderNumber',
                title: '订单号',
                width: '100px',
                formatter: stringFormatter
            }, {
                field: 'code',
                title: '客户代码',
                width: '90px',
                formatter: stringFormatter
            }, {
                field: 'jobTicketNumber',
                title: '工作传票号',
                width: '170px',
                formatter: stringFormatter
            }, {
                field: 'productNumber',
                title: '客户料号',
                width: '170px',
                formatter: stringFormatter
            }, {
                field: 'itemName',
                title: '品名',
                width: '90px',
                formatter: stringFormatter
            }, {
                field: 'spec',
                title: '规格',
                width: '170px',
                formatter: stringFormatter
            }, {
                field: 'unit',
                title: '单位',
                width: '90px',
                formatter: stringFormatter
            }, {
                field: 'storageAmount',
                title: '库存数量',
                width: '150px',
                formatter: stringFormatter
            }, {
                field: 'unitPrice',
                title: '单价',
                width: '90px',
                formatter: stringFormatter
            }, {
                field: 'money',
                title: '金额',
                width: '90px',
                formatter: stringFormatter
            }, {
                field: 'houseName',
                title: '存放仓库',
                width: '170px',
                formatter: stringFormatter
            }, {
                field: 'isAllocation',
                title: '是否调拨',
                width: '150px',
                formatter: stringFormatter
            }, {
                field: 'storageDate',
                title: '入库日期',
                width: '170px',
                formatter: dateFormatter
            }, {
                field: 'operate',
                title: '操作',
                width: '82px',
                formatter: operateFormatter // 自定义方法，添加操作按钮
            }]);
    }

    function operateFormatter(value, row, index) {  // 赋予的参数
        return '<button class="btn btn-success view" data-toggle="modal" data-target="#viewModal" onclick="view('+ index +');">查看</button>';
    }

    changeToolTip();

    // 模态框初始化
    dragTheModalDialog();

    // 初始化销售下拉框（客户信息）
    initSelect($codeSelect, "请输入客户代码", codeFormatter, "/customer-management/getCustomer", 1000, params => {
        return {code: params.term, offset: params.page ? 10 * (params.page - 1) : 0, limit: 10};
    }, result => result.module.rows.map(item => {
        return { id: item.id, text: item.code, name:item.name };
    }), 10);
    function codeFormatter(result) {
        return  '<span title="'+result.name +'">' + result.text +'</span>';
    }

    // 初始化调拨下拉框（仓库信息）
    initSelect($houseNameSelect, "请输入仓库名称", houseNameFormatter, "/warehouse-management/getWarehouse", 1000, params => {
        return { name: params.term, offset: params.page ? 10 * (params.page - 1) : 0, limit: 10, isZero:"是"};
    }, result =>result.module.rows.map(item => {
        return { id: item.id, text: item.name };
    }), 10);
    function houseNameFormatter(result) {
        return  '<span title="'+'">' + result.text +'</span>';
    }

    // 增加下拉框初始化
    let $searchWarehouseSelect = $("#txt_search_house_name");
    function initWareHouseSelect() {
        noParameterPostRequest("/warehouse-management/getWarehouse?limit=100&offset=0&sort=create_time&order=DESC&type=成品仓库&isZero=否", result => {
            $searchWarehouseSelect.empty();
            $searchWarehouseSelect.append("<option value='--请选择--'>--请选择--</option>");
            result.module.rows.forEach(item => $searchWarehouseSelect.append("<option value="+ item.name +">" + item.name + "</option>"));
        }, "GET");
    }

    // 初始化表格数据
    function init() {
        getServerPaging($table, "/finished-goods-repertory/getProductInventoryRepertory", params => {
            return { limit: params.limit, offset: params.offset, sort: "`t_product_storage`.`storage_date`", order: "ASC" };
        });
        initWareHouseSelect();
    }
</script>
<script>
    /** 页面逻辑*/
    // 出库数量改变
    function exportAmountInputChange() {
        let selections = $table.bootstrapTable('getSelections');

        if ($exportAmountInput.val() < 0) {
            swal("操作提示", "出库数量需为正数", "info");
            setInputError($exportAmountInput);
            return;
        }

        if (parseFloat($exportAmountInput.val()) > parseFloat(selections[0].storageAmount)) {
            swal("操作提示", "销售不能超过生产数量", "info");
            setInputError($exportAmountInput);
            return;
        }

        "" === $exportAmountInput.val() ? setInputError($exportAmountInput) : setInputSuccess($exportAmountInput);
    }

    // 调拨数量改变
    function allocationAmountInputChange() {
        let selections = $table.bootstrapTable('getSelections');

        if ($allocationAmountInput.val() < 0) {
            swal("操作提示", "调拨数量需为正数", "info");
            setInputError($exportAmountInput);
            return;
        }

        if (parseFloat($allocationAmountInput.val()) > parseFloat(selections[0].storageAmount)) {
            swal("操作提示", "调拨不能超过生产数量", "info");
            setInputError($allocationAmountInput);
            return;
        }

        "" === $allocationAmountInput.val() ? setInputError($allocationAmountInput) : setInputSuccess($allocationAmountInput);
    }
</script>
<script>
    /** 功能 */
    // 过滤
    function filter() {
        let time = [$("#txt_search_start_time"), $("#txt_search_end_time")];
        if ("" !== time[0][0].validationMessage || "" !== time[1][0].validationMessage) {
            swal("操作提示", "请填写完整的时间", "info");
            return;
        }

        let data = { orderNumber: $("#txt_search_order_number").val(), code: $("#txt_search_code").val(), jobTicketNumber: $("#txt_search_job_ticket_number").val(), isAllocation: $("#txt_search_is_allocation").val(),
            productNumber: $("#txt_search_product_number").val(), itemName: $("#txt_search_item_name").val(), spec: $("#txt_search_spec").val(), houseName: $searchWarehouseSelect.val(), startTime: time[0].val(), endTime: time[1].val() };

        if ("" === data["orderNumber"] && "" === data["code"] && "" === data["jobTicketNumber"] && "" === data["productNumber"] && "" === data["itemName"]
            && "" === data["spec"] && "" === data["houseName"] && "--请选择--" === data["isAllocation"] && "" === data["startTime"] && "" === data["endTime"]) {
            swal("操作提示", "请填写过滤参数", "info");
            return;
        }

        getServerPaging($table, "/finished-goods-repertory/getProductInventoryRepertoryByConditions", params => {
            let result = { limit: params.limit, offset: params.offset, sort: "`t_product_storage`.`storage_date`", order: "ASC", orderNumber: data["orderNumber"], code: data["code"], jobTicketNumber: data["jobTicketNumber"],
                productNumber: data["productNumber"], itemName: data["itemName"], spec: data["spec"], startTime: data["startTime"], endTime: data["endTime"], houseName: data["houseName"], isAllocation: data["isAllocation"]};

            removeEmptyField(result);
            if ("--请选择--" === result["houseName"]) {
                delete result["houseName"];
            }

            if ("--请选择--" === result["isAllocation"]) {
                delete result["isAllocation"];
            }

            return result;
        });
    }

    // 导出excel
    function exportExcel() {
        let selections = $table.bootstrapTable('getSelections');
        if (selections.length === 0) {
            swal("操作提示", "请选择记录", "info");
        } else {
            parameterPostRequest("/finished-goods-repertory/exportExcel", selections, () => loadFile("成品库存信息.xlsx"));
        }
    }

    // 查看
    function view(index) {
        let rows = $("#table").bootstrapTable('getData');
        $("#view_code").text(rows[index].code);
        $("#view_spec").text(rows[index].spec);
        $("#view_storage_amount").text(rows[index].storageAmount);
        $("#view_house_name").text(rows[index].houseName);
        $("#view_product_number").text(rows[index].productNumber);
        $("#view_unit").text(rows[index].unit);
        $("#view_unit_price").text(rows[index].unitPrice);
        $("#view_storage_date").text(formatDateTime(rows[index].storageDate));
    }

    // 成品销售功能
    function initSale() {
        let rows = $table.bootstrapTable('getSelections');
        if (rows.length === 0) {
            swal("操作提示", "请选择记录", "info");
        } else if (rows.length > 1) {
            swal("操作提示", "只能选择一条进行销售", "info");
        } else {
            $("#input_product_number").val(rows[0].productNumber).trigger("change");;
            $("#input_export_amount").val(rows[0].storageAmount);
            $storageDateSelect.html("");
            $('#addModal').modal('show');

            // 初始化销售下拉框（入库日期）
            initSelect($storageDateSelect, "请输入当前记录入库日期", storageDateFormatter, "/finished-goods-repertory/getProductInventoryRepertory", 1000, params => {
                storageDateArray.length = 0;
                return {itemName: rows[0].itemName, spec: rows[0].spec, storageDate: params.term, offset: params.page ? 10 * (params.page - 1) : 0, limit: 10};
            }, result =>result.module.rows.map(item => {
                storageDateArray[i++] = item.storageDate;
                return { id: item.id, itemName: item.itemName, spec: item.spec, text: formatDateTime(item.storageDate)};
            }), 10);
            function storageDateFormatter(result) {
                return  '<span title="'+ "品名：" + result.itemName + " | " + "规格：" + result.spec  + " | " + "入库日期：" + result.text +'" >' + result.text +'</span>';
            }
        }
    }
    function sale() {
        if (0 !== $codeSelect.select2('data').length) {
            let selections = $table.bootstrapTable('getSelections');
            let resultAmount = selections[0].storageAmount;
            let amount1 = parseInt(resultAmount);
            let amount2 = parseInt($("#input_export_amount").val());
            if (selections[0].storageAmount === 0) {
                swal("操作提示", "库存无剩余，请进行下一批出库", "info");
            }
            let data = {
                productInventoryId: selections[0].id,
                number: $("#input_export_number").val(),
                customerId: $codeSelect.select2('data')[0].id,
                orderNumber: $("#input_bill_of_sale_number").val(),
                amount: $("#input_export_amount").val(),
                date: $("#input_export_date").val(),
                remark: $("#input_remark").val()
            };
            if ("" === data.productInventoryId || "" === data.number || "" === data.customerId || "" === data.orderNumber || "" === data.amount || "" === data.date) {
                swal("操作提示", "请输入必输入项", "info");
                return;
            }

            if (data.amount < 0 || selections[0].storageAmount < 0 || parseFloat(data.amount) > parseFloat(selections[0].storageAmount)) {
                swal("操作提示", "请按照要求填写", "info");
            } else {
                for (let j = 0; j < i; ++j) {
                    if (Date.parse(($storageDateSelect.select2('data')[0].text).replace(/-/g, "/")) > Date.parse(formatDateTime((storageDateArray[j])).replace(/-/g, "/"))) {
                        swal("操作提示", "请按照入库顺序出库！", "info");
                        return;
                    }
                }
                parameterPostRequest("/finished-goods-repertory/productInventorySale", data, () => {
                    let data = {
                        productStorageId: selections[0].productStorageId,
                        storageAmount: (amount1 - amount2).toString()
                    };
                    parameterPostRequest("/finished-goods-repertory/updateStorageAmount", data, () => {
                        $('#addModal').modal('hide');
                        swal("正确", "销售成功", "success");
                        init();
                    });
                });
            }
        } else {
            swal("操作提示", "请输入必输入项", "info");
        }
    }

    // 成品调拨功能实现
    function initAllocation() {
        let rows = $table.bootstrapTable('getSelections');
        if (rows.length === 0) {
            swal("操作提示", "请选择记录", "info");
        } else if (rows.length > 1) {
            swal("操作提示", "只能选择一条进行调拨", "info");
        } else {
            $("#input_spec").val(rows[0].spec);
            $("#input_item_name").val(rows[0].itemName);
            $("#input_storage_amount").val(rows[0].storageAmount);
            $("#input_warehouse").val(rows[0].houseName);
            $('#allocationModal').modal('show');
        }
    }
    function allocation() {
        if (0 !== $houseNameSelect.select2('data').length) {
            let selections = $table.bootstrapTable('getSelections');
            let resultAmount = selections[0].storageAmount;
            let amount1 = parseFloat(resultAmount);
            let amount2 = parseFloat($("#input_allocation_amount").val());

            let data = {
                productInventoryId: selections[0].id,
                amount: $("#input_allocation_amount").val(),
                warehouseId: $houseNameSelect.select2('data')[0].id,
                allocationDate: $("#input_allocation_date").val(),
                remark: $("#input_allocation_remark").val(),
            };

            if ("" === data.amount || "" === data.productInventoryId || "" === data.allocationDate ) {
                swal("操作提示", "请输入必输入项", "info");
                return;
            }

            if (data.amount < 0 || selections[0].storageAmount < 0 || parseFloat(data.amount) > parseFloat(selections[0].storageAmount)) {
                swal("操作提示", "请按照要求填写", "info");
            } else {
                parameterPostRequest("/finished-goods-repertory/productAllocation", data, () => {
                    let data = {
                        productStorageId: selections[0].productStorageId,
                        storageAmount: (amount1 - amount2).toString()
                    };
                    parameterPostRequest("/finished-goods-repertory/updateStorageAmount", data, () => {
                        $('#allocationModal').modal('hide');
                        swal("正确", "调拨成功", "success");
                        init();
                    });
                });
            }
        } else {
            swal("操作提示", "请输入必输入项", "info");
        }
    }
</script>

</body>

</html>